package com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.commandtype;


import com.zx.idc.backend.gui.api.commom.entity.CommandModel;
import com.zx.idc.backend.gui.api.management.basicdata.query.IdcBasicDataQueryService;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.CommandOperating;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.CommandType;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.entity.Option;
import com.zx.idc.xml.entity.idcinfomanage.IdcInfoManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import static com.zx.idc.common.attributes.SchemaFileNameAttributes.BASE_DATA_QUERY;

/**
 * Created by hasee on 2019/2/21.
 * 基础数据查询
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class BaseDataQueryImpl extends CommandOperating<IdcInfoManage> implements CommandType {
    private static final int NUM = 5;
    @Autowired
    private IdcBasicDataQueryService idcBasicDataQueryService;

    @Override
    public boolean isMatch(Option option) {
        return option.getType() == NUM;
    }

    @Override
    public String execute(String xmlData, CommandModel commandModel) {
        //数据格式验证通过则扔到队列返回结果
        return receiveCommand(xmlData, commandModel, getSchemaFilePath(BASE_DATA_QUERY));
    }

    /**
     * 覆盖该方法执行指令
     *
     * @param idcInfoManage 实体bean
     * @param commandModel  指令mode
     */
    @Override
    public void task(IdcInfoManage idcInfoManage, CommandModel commandModel) {
        idcBasicDataQueryService.commandQuery(idcInfoManage, commandModel);
    }
}
